package com.cskaoyan.shopping.api;

import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemServiceResponse;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.mall.dto.ProductDetailServiceResponse;
import com.cskaoyan.shopping.service.ICartService;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther cskaoyan
 */
@RestController
public class OrderApiImpl {

    @Autowired
    IProductService productService;


    @Autowired
    ICartService iCartService;

    @DeleteMapping(value = "/rpc/cart/items")
    ClearCartItemServiceResponse clearCartItemByUserID(@RequestBody ClearCartItemRequest request){
        iCartService.deleteCartItemOfOrder(request);
        ClearCartItemServiceResponse response = new ClearCartItemServiceResponse();
        response.setCode("200");
        response.setMsg("删除成功");
        return response;
    }


    @GetMapping(value = "/rpc/product/detail")
    ServiceCallResponse<ProductDetailDto> getProductDetail(@RequestParam("id") Long id) {
        ProductDetailDto productDetail = productService.getProductDetail(id);
        // 服务调用的返回值
        ServiceCallResponseUtil<ProductDetailDto> responseUtil = new ServiceCallResponseUtil<>();
        return responseUtil.ok(productDetail);
    }
}
